import { PaginationResult } from "../../models";
import {
  ListItem,
  ParManufacturerItem,
  ParProductArchivesItem,
  ParProductFaultItem,
  ParProductItem,
  ParProductModelItem,
  ParProductTypesItem,
  ParProtocolsItem,
  ProductBrandItem,
  ProductCategory,
  ProductItem,
  ProductModelItem,
  ProductModelList,
  ProductModelSearch,
  UpgradeItem,
} from "./models";
import req from "/@/api/req";

export enum Api {
  // 产品类别
  categoryPage = "api/v1/products/category/page", // 产品类别查询
  categoryGet = "api/v1/products/category/get", // 产品类别详情
  categoryDel = "api/v1/products/category/batch_delete",
  categorySave = "api/v1/products/category/save",
  // 产品类型
  typesPage = "api/v1/products/types/tree",
  typesSave = "api/v1/products/types/save",
  typesGet = "api/v1/products/types/get",
  typesDel = "api/v1/products/types/batch_delete",
  // 产品厂商
  manufacturersPage = "api/v1/products/manufacturers/page", // 产品厂商查询
  manufacturersGet = "api/v1/products/manufacturers/get", // 产品厂商详情
  manufacturersDel = "api/v1/products/manufacturers/batch_delete",
  manufacturersSave = "api/v1/products/manufacturers/save",
  // 产品品牌
  brandsPage = "api/v1/products/brands/page", // 产品品牌查询
  brandsGet = "api/v1/products/brands/get", // 产品品牌详情
  brandsDel = "api/v1/products/brands/batch_delete",
  brandsSave = "api/v1/products/brands/save",
  // 产品中心
  productsPage = "api/v1/products/page", // 产品中心查询
  productsGet = "api/v1/products/get", // 产品中心详情
  productsDel = "api/v1/products/batch_delete",
  productsSave = "api/v1/products/save",
  // 产品规格型号
  specificationsPage = "api/v1/products/specifications/tree",
  specificationsGet = "api/v1/products/specifications/get",
  specificationsDel = "api/v1/products/specifications/batch_delete",
  specificationsSave = "api/v1/products/specifications/save",
  // 故障信息表
  faultsPage = "api/v1/products/faults/page",
  faultsGet = "api/v1/products/faults/get",
  faultsDel = "api/v1/products/faults/batch_delete",
  faultsSave = "api/v1/products/faults/save",
  // 产品固件升级OTA
  otaPackagesPage = "api/v1/products/ota_packages/page",
  otaPackagesGet = "api/v1/products/ota_packages/get",
  otaPackagesDel = "api/v1/products/ota_packages/batch_delete",
  otaPackagesSave = "api/v1/products/ota_packages/save",
  otaPackagesUpgrade = "api/v1/products/ota_upgrades/upgrade",
  checkPass = "api/v1/products/executions/check_pass",
  // 协议管理模块
  protocolsPage = "api/v1/product/protocols/page",
  protocolsGet = "api/v1/product/protocols/get",
  protocolsDel = "api/v1/product/protocols/batch_delete",
  protocolsSave = "api/v1/product/protocols/save",
  protocolsUrl = "api/v1/product/protocols/templates/get",
  protocolsImport = "api/v1/product/protocols/import",
  // 下拉数据
  brandList = "api/v1/products/dropdown/brands", // 品牌下拉数据
  categoryList = "api/v1/products/dropdown/category", // 类别下拉数据
  manufacturersList = "api/v1/products/dropdown/manufacturers", // 厂商下拉数据
  seriesList = "api/v1/products/dropdown/series", // 产品系列
  // 产品档案
  archivesPage = "api/v1/products/archives/list",
  archivesDel = "api/v1/products/archives/batch_delete",
  archivesSave = "api/v1/products/archives/save",
  // 更新记录
  listProductOtaUpgrades = "api/v1/products/ota_upgrades/list",
}

export interface AddUserItemParams {
  userGroupId: string;
  userIds: Array<string>;
}
// 获取产品类别详情
export function categoryGet(data: { productCategoryId: string }) {
  return req.post<ProductCategory>({
    url: Api.categoryGet,
    data,
  });
}
// 获取产品类别详情
export function getTypesPage(data?: { searchText?: string; isEnable?: boolean }) {
  return req.post<ParProductTypesItem[]>({
    url: Api.typesPage,
    data,
  });
}
// 保存产品类型
export function typesSave(data: ParProductTypesItem) {
  return req.post<boolean>({
    url: Api.typesSave,
    data,
  });
}
// 删除产品
export function productsDel(data: string[]) {
  return req.post<boolean>({
    url: Api.productsDel,
    data,
  });
}
// 删除产品品牌
export function brandsDel(data: string[]) {
  return req.post<boolean>({
    url: Api.brandsDel,
    data,
  });
}
// 删除产品厂商
export function manufacturersDel(data: string[]) {
  return req.post<boolean>({
    url: Api.manufacturersDel,
    data,
  });
}
// 删除产品模型
export function specificationsDel(data: string[]) {
  return req.post<boolean>({
    url: Api.specificationsDel,
    data,
  });
}
// 删除产品类型
export function typesDel(data: string[]) {
  return req.post<boolean>({
    url: Api.typesDel,
    data,
  });
}
export function categoryDel(data: string[]) {
  return req.post<boolean>({
    url: Api.categoryDel,
    data,
  });
}
// 获取产品品牌下拉
export function productsPage() {
  return req.post<PaginationResult<ParProductItem>>(
    {
      url: Api.productsPage,
      data: {
        current: 1,
        model: {},
        size: 999,
      },
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 获取产品品牌下拉
export function brandList(data?: { searchText?: string; manufacturerId?: string }) {
  return req.post<ListItem[]>(
    {
      url: Api.brandList,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 获取产品类别下拉
export function categoryList(data?: { searchText?: string }) {
  return req.post<ListItem[]>(
    {
      url: Api.categoryList,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 获取产品厂商下拉
export function manufacturersList(data?: { searchText?: string }) {
  return req.post<ListItem[]>(
    {
      url: Api.manufacturersList,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 获取产品厂商下拉
export function seriesList(data?: { searchText?: string }) {
  return req.post<ListItem[]>(
    {
      url: Api.seriesList,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 新增产品
export function addProduct(data: ParProductItem) {
  return req.post<boolean>({
    url: Api.productsSave,
    data,
  });
}
export function specificationsSave(data: ParProductModelItem) {
  return req.post<boolean>({
    url: Api.specificationsSave,
    data,
  });
}
export function specificationsGet(specificationId: string) {
  return req.post<ProductModelItem>({
    url: Api.specificationsGet,
    data: { specificationId },
  });
}
export function specificationsPage(data?: ProductModelSearch) {
  return req.post<ProductModelList[]>({
    url: Api.specificationsPage,
    data,
  });
}
export function getProduct(productId: string) {
  return req.post<ParProductItem>({
    url: Api.productsGet,
    data: { productId },
  });
}
export function addFault(data: ParProductFaultItem) {
  return req.post<boolean>({
    url: Api.faultsSave,
    data,
  });
}
export function addArchives(data: ParProductArchivesItem) {
  return req.post<boolean>({
    url: Api.archivesSave,
    data,
  });
}
export function archivesPage(data: { searchText?: string; productId?: string }) {
  return req.post<ParProductArchivesItem[]>({
    url: Api.archivesPage,
    data,
  });
}
export function archivesDel(productArchiveIds?: string[]) {
  return req.post<ParProductArchivesItem[]>({
    url: Api.archivesDel,
    data: productArchiveIds,
  });
}
export function otaPackagesSave(data: any) {
  return req.post<boolean>({
    url: Api.otaPackagesSave,
    data,
  });
}
export function otaPackagesGet(otaPackageId: string) {
  return req.post<boolean>({
    url: Api.otaPackagesGet,
    data: { otaPackageId },
  });
}
export function otaPackagesDel(data: string[]) {
  return req.post<boolean>({
    url: Api.otaPackagesDel,
    data,
  });
}
export function listProductOtaUpgrades(productId: string) {
  return req.post<UpgradeItem[]>({
    url: Api.listProductOtaUpgrades,
    data: { productId },
  });
}
// 初始密码 aiot2023
export function checkPass(data: { password: string }) {
  return req.post<boolean>({
    url: Api.checkPass,
    data,
  });
}
// 初始密码 aiot2023
export function otaPackagesUpgrade(otaPackageId: string) {
  return req.post<boolean>({
    url: Api.otaPackagesUpgrade,
    data: { otaPackageId },
  });
}
export function protocolsSave(data: ParProtocolsItem) {
  return req.post<boolean>({
    url: Api.protocolsSave,
    data,
  });
}
export function protocolsImport(data: FormData) {
  return req.post<boolean>({
    url: Api.protocolsImport,
    data,
  });
}
export function protocolsUrl() {
  return req.post<any>({
    url: Api.protocolsUrl,
    data: {},
  });
}
export function protocolsDel(data: string[]) {
  return req.post<boolean>({
    url: Api.protocolsDel,
    data,
  });
}
